package kr.ac.kaist.savehearts.status;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapOverlays extends ItemizedOverlay<OverlayItem> {

	private static final String TAG = MapOverlays.class.getSimpleName();
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	private Drawable defaultIcon = null;
	private Context mContext = null;
	
	public MapOverlays(Drawable defaultIcon) {
		super(boundCenterBottom(defaultIcon));
		this.defaultIcon = defaultIcon;
	}
	
	public MapOverlays(Drawable defaultIcon, Context context) {
		this(defaultIcon);
		this.mContext = context;
	}
	
	public void addOverlay(OverlayItem overlay) {
		this.mOverlays.add(overlay);
		populate();
	}
	
	public void clearOverlays() {
		this.mOverlays.clear();
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
	
}
